package com.billdowney.qq.robot.plugins.provide;

import com.billdowney.qq.robot.annotations.HookMethod;
import com.billdowney.qq.robot.annotations.HookNotice;
import com.billdowney.qq.robot.plugins.RobotPlugin;
import com.billdowney.qq.robot.plugins.RobotPluginContent;
import com.billdowney.qq.robot.util.MessageUtil;
import lombok.extern.slf4j.Slf4j;
import net.mamoe.mirai.message.data.Image;
import net.mamoe.mirai.message.data.MessageChainBuilder;
import org.springframework.stereotype.Component;

/**
 * 历史消息插件
 *
 * @author BillDowney
 */
@Component
@Slf4j
@HookNotice(name = "历史消息插件", start = true)
public class HistoryMsgRobotPlugin implements RobotPlugin {

    @HookMethod(start = "历史图片", desc = "{图片id}")
    public void historyImage(RobotPluginContent content) {
        try {
            MessageChainBuilder builder = MessageUtil.createBuilder();
            Image image = Image.fromId(content.getFilterContent());
            builder.add("图片地址：" + Image.queryUrl(image));
            builder.add(image);
            content.putReplyMessage(builder);
        } catch (Exception e) {
            log.error("图片消息添加失败", e);
            content.putReplyMessage(e.getMessage());
        }
    }
}
